var ztreejs=function(){
	
	this.protype={};//框架参数
	this.newListArr=[];//新的源数组
	this.selectarr=[];//选择数组	
	
	//暂定三级深度
	this.firstLaver;//一级对象
	this.secoundLavel;//二级对象
	this.threeLavel;//三级对象
}
ztreejs.prototype.ztreetype=function(t){//获取参数并验证
	if(!t.lavelNum||!t.nodeName){
		console.log("参数错误")
		return false;
	}
	ztree.protype=t;//获取框架参数
	ztree.statusarr(ztree.protype.citydata);
}

ztreejs.prototype.statusarr=function(arr){
	getJson(arr)
	function getJson(arr){
		for(var i=0;i<arr.length;i++){
			//console.log(arr[i].listArr)
			if(arr[i].listArr){
				arr[i]["selekey"]='';
				getJson(arr[i].listArr);
			}
			//listArr[k]["selekey"]='2';
		}
	}
	ztree.firstRendering();//一级渲染触发
}

ztreejs.prototype.seleFirst=function(pn){
	//pn代表序列号
	ztree.protype.citydata[pn].selekey='1';
	if(ztree.firstLaver!=pn){
		ztree.firstLaver=pn;
	}
	ztree.twoRendering(pn);//二级渲染触发
}

ztreejs.prototype.firstRendering=function(){//渲染一级数组
	var domname=ztree.protype.el;
	var dom=document.getElementById(domname);
	dom.innerHTML='';//清空dom
	//dom渲染
	for(var i =0;i<ztree.protype.citydata.length;i++){
		var statusclass='';
		if(ztree.protype.citydata[i].selekey!=''){
			statusclass='selestatus';
		}
		var html = '<li onclick="ztree.seleFirst('+i+')" class="'+statusclass+'">'+ztree.protype.citydata[i].name+'</li>';
		dom.insertAdjacentHTML('beforeend', html)
	}	
}

ztreejs.prototype.backlaver=function(l){
	//l代表层级
	switch(l){
		case 0:
			console.log("没有上一级")
			break;
		case 1:
			ztree.firstRendering();//重新渲染第一层级
			break;
		case 2:
			ztree.twoRendering(ztree.firstLaver);//重新渲染第二层级
			break;
		default:
			console.log("没有了");
			break;
	}
}

ztreejs.prototype.twoRendering=function(pn){//渲染二级数组 pn代表父级序列
	
	var domname=ztree.protype.el;
	var dom=document.getElementById(domname);
		dom.innerHTML='';
	//dom渲染
	for(var i =0;i<ztree.protype.citydata[pn].listArr.length;i++){
		var html = '<li onclick="seleFirst('+i+')">'+ztree.protype.citydata[pn].listArr[i].name+'</li>';
		dom.insertAdjacentHTML('beforeend', html)
	}	
}

var ztree=new ztreejs();
